/*
 * Project: Flying Lantern
 * File: CGame.go
 * Desc: Entry point for game.
 * License: MIT
 */

package main

import (
	"./fl"
	"github.com/0xe2-0x9a-0x9b/Go-SDL/sdl"
	"log"
)

func main() {

	// Initialize our game object
	game := fl.CGame{}
	game.Init()

	// Initialize SDL
	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		log.Fatal(sdl.GetError())
	}

	// Initialize our screen/rendering surface
	var screen = sdl.SetVideoMode(640, 480, 32, sdl.RESIZABLE)

	if screen == nil {
		log.Fatal(sdl.GetError())
	}

	// Set our window caption
	sdl.WM_SetCaption("Oh my god JC a bomb", "")

	// Load our texture(s)
	tm := fl.CTextureManager{}
	tm.Init()
	tm.LoadTexture("img/176px-JCDenton2.png", "JC")

	// Our main loop
	for game.IsRunning() {

		game.Update()

		// Clear screen, draw image, swap buffers
		screen.FillRect(nil, 0)
		screen.Blit(&sdl.Rect{int16(25), int16(25), 0, 0}, tm.GetTexture("JC"), nil)
		screen.Flip()
	}

	// Overzealous Cleanup
	tm.FreeAllTextures()
	screen.Free()
	sdl.Quit()
}
